package org.smart4j.chapter1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Currency;
import java.util.Date;

/**
 * @author: x
 * @version: 1.0
 * @date: 2020/5/29
 * @description:
 **/
/**
 * 关于WebServlet注解的解释
 * WebServlet注解是servlet3.0的特性，不需要我们在web.xml中配置该servlet并发布该servlet了，直接使用该注解就行了。
**/
@WebServlet("/hello") //配置请求路径，并对外发布servlet服务
public class HelloServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = dateFormat.format(new Date());
        System.out.println(currentTime);
        request.setAttribute("currentTime",currentTime);
        request.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(request,response);
    }


}
